﻿using System;
using Autofac;
using Autofac.Integration.Mvc;
using Inovout.Component;

namespace Inovout.Web.Mvc
{
    public class MvcComponentResolver : IComponentResolver
    {
        protected ILifetimeScope Container
        {
            get { return AutofacDependencyResolver.Current.RequestLifetimeScope; }
        }
        public bool IsRegistered<TService>()
        {
            return Container.IsRegistered<TService>();
        }
        public object Resolve(Type serviceType)
        {
            return Container.Resolve(serviceType);
        }
        public TService Resolve<TService>(Type serviceType)
        {
            return (TService)Resolve(serviceType);
        }

        public TService Resolve<TService>()
        {
            return Container.Resolve<TService>();
        }


        public bool IsRegistered(Type serviceType)
        {
            return Container.IsRegistered(serviceType);
        }

        public IComponentResolver BeginLifetimeScope()
        {
            throw new NotImplementedException();
        }

        public void Dispose()
        {
            //if (Container != null)
            //{
            //    Container.Dispose();
            //}
        }
    }
}
